package com.yulinlin.admin.core.controller;

import com.yulinlin.admin.core.domain.SuperEntity;
import com.yulinlin.admin.core.domain.po.PagePo;
import com.yulinlin.admin.core.domain.vo.PageVo;
import com.yulinlin.admin.core.service.ISuperService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.List;

public class SuperController<E extends SuperEntity<E>>  {


    @Autowired
    private ISuperService<E> service;

    @ApiOperation("根据id查询数据")
    @RequestMapping(value = "/findById",method = RequestMethod.POST)
    public E findById(String id) {
        return service.findById(id);
    }


    @ApiOperation("批量删除数据")
    @RequestMapping(value = "/deleteByIdIn",method = RequestMethod.POST)
    public int deleteByIdIn(List<Long> coll) {
        return service.deleteByIdIn(coll);
    }

    @ApiOperation("添加或更新一个数据")
    @RequestMapping(value = "/saveOne",method = RequestMethod.POST)
    public int saveOne(E obj) {
        if(obj.getId() == null)
        {
            return service.insertOne(obj);
        }  else{
            return service.updateOne(obj);
        }
    }


    @ApiOperation("所有数据")
    @RequestMapping(value = "/all",method = RequestMethod.POST)
    public List<E> all() {
        return service.all();
    }

    @ApiOperation("分页查询")
    @RequestMapping(value = "/page",method = RequestMethod.POST)
    public PageVo<E> page(PagePo<E> po) {
        return null;
    }
}
